| - (Unary Negation) This operator is used to simply negate the value it is being assigned to. The value it is used with must be of the "Number" data type, so an attempt is made to convert the contents of the variable to a number before being negated. It should be noted that the origianl value of the variable won't be altered in any way - the original value will stay the same, with only the returned value being negated. syntax: -number EXAMPLE variableOne = new String("50"); variableTwo = -variableOne; document.write(The value of variableTwo is " + variableTwo); This example declares two variables. The first variable, variableOne, is loaded with the string value for "50". The second variable is used with the Unary Negation operator to negate the value of the first variable, variableOne. Since any data type other than a number will be converted to a number, the string value within variableOne, which is "50" will be converted to the Number data type. It will then be negated for the second variable, variableTwo. The answer then, written to the browser screen, is "The value of variableTwo is -50". |